/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaz;

import Control.DES;
import Control.Operaciones;
import Entidad.Reporte;
import java.util.Calendar;
import javax.swing.JOptionPane;
import Control.ES;

/**
 *
 * @author Omar Beltran
 */
public class InterfazInicio extends javax.swing.JDialog {
    Operaciones operaciones = new Operaciones();
    /**
     * Creates new form InterfazInicio
     */
    public InterfazInicio(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.setLocation(500, 200);
        Calendar fecha = Calendar.getInstance();
        initComponents();
        txtAreaOutput.setText("Current Date: "+fecha.get(Calendar.DATE)
                                          +"/"+fecha.get(Calendar.MONTH)
                                          +"/"+fecha.get(Calendar.YEAR));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblWeatherReport = new javax.swing.JLabel();
        lblValuestoForecast = new javax.swing.JLabel();
        txtWeatherReport = new javax.swing.JTextField();
        txtValuestoForecast = new javax.swing.JTextField();
        btnAdd = new javax.swing.JButton();
        btnDeleteLast = new javax.swing.JButton();
        btnDeleteAll = new javax.swing.JButton();
        btnForecast = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtAreaOutput = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        lblWeatherReport.setText("Weather Report");

        lblValuestoForecast.setText("Values to Forecast");

        txtValuestoForecast.setText("0");

        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnDeleteLast.setText("Delete Last");
        btnDeleteLast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteLastActionPerformed(evt);
            }
        });

        btnDeleteAll.setText("Delete All");
        btnDeleteAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteAllActionPerformed(evt);
            }
        });

        btnForecast.setText("Forecast");
        btnForecast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnForecastActionPerformed(evt);
            }
        });

        txtAreaOutput.setColumns(20);
        txtAreaOutput.setRows(5);
        txtAreaOutput.setText("Current Data:");
        txtAreaOutput.setEnabled(false);
        jScrollPane1.setViewportView(txtAreaOutput);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblValuestoForecast)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtValuestoForecast, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblWeatherReport)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(txtWeatherReport, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 57, Short.MAX_VALUE)
                                .addComponent(btnAdd)
                                .addGap(18, 18, 18)
                                .addComponent(btnDeleteLast)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(btnDeleteAll)
                                    .addComponent(btnForecast))))))
                .addGap(35, 35, 35))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblWeatherReport)
                    .addComponent(txtWeatherReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblValuestoForecast)
                    .addComponent(txtValuestoForecast, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnDeleteLast)
                    .addComponent(btnDeleteAll))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnForecast)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        
        if(operaciones.isNumber(txtWeatherReport.getText())){
            
            if(operaciones.validarDatos(txtWeatherReport.getText())){
                operaciones.addReporte(new Reporte(txtWeatherReport.getText(),Calendar.getInstance()));
                JOptionPane.showMessageDialog(this, "DATO AGREGADO CORRECTAMENTE", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
            }    
            
            else
                JOptionPane.showMessageDialog(this, "DEDE INGRESAR UN VALOR", "ERROR", JOptionPane.ERROR_MESSAGE);
            
            operaciones.mostrarReportes(operaciones.getReportes().size());
        }
        else
            JOptionPane.showMessageDialog(this, "DEDE INGRESAR SOLAMENTE VALORES NUMERICOS", "ERROR", JOptionPane.ERROR_MESSAGE);
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnDeleteAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteAllActionPerformed
        
        if (operaciones.removeAllReporte())
            JOptionPane.showMessageDialog(this, "TODOS LOS DATOS HAN SIDO ELIMINADOS", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        else
            JOptionPane.showMessageDialog(this, "NO HAY DATOS. NO ES POSIBLE ELIMINAR. LISTA VACIA", "ERROR", JOptionPane.ERROR_MESSAGE);
        
    }//GEN-LAST:event_btnDeleteAllActionPerformed

    private void btnDeleteLastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteLastActionPerformed
    
        if (!(operaciones.removeLast()))
            JOptionPane.showMessageDialog(this, "NO HAY DATOS. NO ES POSIBLE ELIMINAR. LISTA VACIA", "ERROR", JOptionPane.ERROR_MESSAGE);
        else
            JOptionPane.showMessageDialog(this, "SE HA ELIMINADO EL ULTIMO DATO INGRESADO", "INFORMACION", JOptionPane.INFORMATION_MESSAGE);
        
    }//GEN-LAST:event_btnDeleteLastActionPerformed

    private void btnForecastActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnForecastActionPerformed
        
        if(operaciones.isNumber(txtValuestoForecast.getText())){
            
            if ((operaciones.validarDatos(Integer.parseInt(txtValuestoForecast.getText())))== 0)
                JOptionPane.showMessageDialog(this, "DEBE ESCRIBIR UN NUMERO DIFERENTE DE CERO", "ERROR", JOptionPane.ERROR_MESSAGE);
            
            else 
                if ((operaciones.validarDatos(Integer.parseInt(txtValuestoForecast.getText())))== 2)
                    JOptionPane.showMessageDialog(this, "DEBE INGRESAR MINIMO 5 DATOS", "ERROR", JOptionPane.ERROR_MESSAGE);
                else
                    operaciones.mostrarPronosticos();
                    ES exponencial= new ES();
                    exponencial.forecast(operaciones.getReportes());
        }
        else
            JOptionPane.showMessageDialog(this, "DEDE INGRESAR SOLAMENTE VALORES NUMERICOS", "ERROR", JOptionPane.ERROR_MESSAGE);
        

        /*
         * prueba de algoritmo DES
         */
        

    }//GEN-LAST:event_btnForecastActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(InterfazInicio.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                InterfazInicio dialog = new InterfazInicio(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDeleteAll;
    private javax.swing.JButton btnDeleteLast;
    private javax.swing.JButton btnForecast;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblValuestoForecast;
    private javax.swing.JLabel lblWeatherReport;
    private javax.swing.JTextArea txtAreaOutput;
    private javax.swing.JTextField txtValuestoForecast;
    private javax.swing.JTextField txtWeatherReport;
    // End of variables declaration//GEN-END:variables
}
